(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

不用行为客户端向行为服务器发送目标

Description: 教程展示了一些通过不创建行为客户端向行为服务器发送一个目标的方法

Keywords: action_server, axclient

Tutorial Level: BEGINNER

运行节点

我们通过使用已经安装的ROS turtle_actionlib包来展示结果,首先我们初始化一个turtlesim节点,在新终端运行roscore为开始

$ roscore

在其他终端,运行turtlesim

$ rosrun turtlesim turtlesim_node

运行完成'turtlesim'后,运行turtlesim_actionlib包中的服务器

$ rosrun turtle_actionlib shape_server

在其他终端中,我们检查行为服务器的话题是否完成创建

$ rostopic list

如果一切正常,你可以看到类似如下输出:

/rosout
/rosout_agg
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
/turtle_shape/cancel
/turtle_shape/feedback
/turtle_shape/goal
/turtle_shape/result
/turtle_shape/status

As you can see, the topics with names /cancel, /feedback, /goal, /result and /status shows that the shape_server is running and has created the action topics. So, there is 2 ways to send a goal to the action_server without an action client.

Send a Goal to Action Server

Use the rostopic pub direct in a terminal

As the /goal topic is a normal topic, can be publish normally, so, in a new terminal:

$ rostopic pub /turtle_shape/goal turtle_actionlib/ShapeActionGoal "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: ''
goal_id:
  stamp:
    secs: 0
    nsecs: 0
  id: ''
goal:
  edges: 0
  radius: 0.0" 

An easy way of use this approach is start typing and always press TAB, so the system completes the name and type of the topic and, also, the content of the msg. After the appears complete, change the values of the goal, like the example below:

$ rostopic pub /turtle_shape/goal turtle_actionlib/ShapeActionGoal "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: ''
goal_id:
  stamp:
    secs: 0
    nsecs: 0
  id: ''
goal:
  edges: 3
  radius: 1.0" 

Sending this goal, the turtle at turtlesim should draw a triangle similar to this:

triangle_action.png

Use axclient from actionlib

The actionlib offers a graphical way to send goal to action server. To use this interface, run in a terminal

$ rosrun actionlib axclient.py /name_of_the_action

In our case:

$ rosrun actionlib axclient.py /turtle_shape

An window similar to this should open:

axclient.png

In this GUI, there is the areas ti the Goal, Feedback and Result. We can use this interface to send the goal with edges=4 and radius=2.0. Change the values at the Goal area and press the SEND GOAL button. After that, the turtle at turtlesim should draw a square. Sending the goal to the action server.

send_goal.png

In this image, the CANCEL GOAL button change to active, so the action can be preempted.

cancel_goal.png

After the action finished successfully, the GUI shows the Result.

finish_goal.png

And the turtle drew the square as spectated:

turtle_square.png

Wiki: cn/actionlib_tutorials/Tutorials/Calling Action Server without Action Client (last edited 2020-05-15 01:04:10 by Playfish)